#include <am.h>
#include <klib.h>
#include <klib-macros.h>

#define IP_BASE_ADDR 0x10004000
#define REG_LCR *((volatile uint32_t *)(IP_BASE_ADDR + 0))
#define REG_DIV *((volatile uint32_t *)(IP_BASE_ADDR + 4))
#define REG_TRX *((volatile uint32_t *)(IP_BASE_ADDR + 8))
#define REG_FCR *((volatile uint32_t *)(IP_BASE_ADDR + 12))
#define REG_LSR *((volatile uint32_t *)(IP_BASE_ADDR + 16))

int main(){
    putstr("uart test\n");
    REG_LCR = (uint32_t) 0x0;
    REG_DIV = (uint32_t) 0x364;
    REG_FCR = (uint32_t) 0xF;
    REG_FCR = (uint32_t) 0xC;
    REG_LCR = (uint32_t) 0x1F;

    uint32_t val = (uint32_t) 0x41;
    for(int i = 0; i < 48; ++i) { 
        while(((REG_LSR & 0x100) >> 8) == 1);
        REG_TRX = (uint32_t)(val + i);
    }

    return 0;
}
